function [pi d] = Calculate_pi_function(cum_Dtime_j_14)

global epsilon_weekday kappa ncity E_weekday w d_GIS delta_j delta_t

d_GIS(:,26)=0;
cum_Dtime_j_14(26)=0; % home sector

cum_Dtime_t_14(:,1)=ones(25,1)*sum(cum_Dtime_j_14);
cum_Dtime_t_14(26,1)=0; % home sector

% Calculate top places to visit during weekdays and weekends
cum_Vtime_j_14=Calculate_V_function(cum_Dtime_j_14);
cum_Vtime_j_14(26)=0;

    for a=1:2
    for d1=1:ncity
        for d2=1:ncity+1
            d(d1,d2,a)=exp(kappa*d_GIS(d1,d2)+delta_j(1,a)*log(cum_Dtime_j_14(d2)+1)+delta_j(2,a)*log(cum_Vtime_j_14(d2)+1)+delta_t(1,a)*log(cum_Dtime_t_14(d2)+1));
        end
    end
    end
    for a=1:2
    for d1=1:ncity % given residential choice
        % calculate sum
        sum_denominator=0;
        for d2=1:ncity+1
            sum_denominator=sum_denominator+E_weekday(d2,a)*(w(d2,a)/d(d1,d2,a))^epsilon_weekday;
        end
        for d2=1:ncity+1
            pi(d1,d2,a)=E_weekday(d2,a)*(w(d2,a)/d(d1,d2,a))^epsilon_weekday/sum_denominator;
        end
    end
    end

end